package cn.tedu.boyou.website.controller;

import cn.tedu.boyou.acticle.domain.MallGoods;
import cn.tedu.boyou.acticle.service.IMallGoodsService;
import cn.tedu.boyou.comment.domain.VirtualComment;
import cn.tedu.boyou.comment.domain.VirtualzcComment;
import cn.tedu.boyou.comment.service.IVirtualCommentService;
import cn.tedu.boyou.comment.service.IVirtualzcCommentService;
import cn.tedu.boyou.common.query.MallGoodsQuery;
import cn.tedu.boyou.common.query.VirtualCommentQuery;
import cn.tedu.boyou.common.query.VirtualzcCommentQuery;
import cn.tedu.boyou.common.util.AjaxResult;
import cn.tedu.boyou.member.domain.UserInfo;
import cn.tedu.boyou.website.annotation.UserParam;
import com.alibaba.dubbo.config.annotation.Reference;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@RequestMapping("mall")
@Controller
public class MallController {

    @Reference
    private IMallGoodsService mallGoodsService;
    @Reference
    private IVirtualCommentService virtualCommentService;
    @Reference
    private IVirtualzcCommentService virtualzcCommentService;

    /**
     * 博游周边
     * @return
     */
    @RequestMapping("things")

    public String things(Model model,@ModelAttribute("qo")MallGoodsQuery qo){
        //goods(没有简介)
        /*List<MallGoods> goods = mallGoodsService.queryByGoodsByDate(qo);
        model.addAttribute("goods", goods);*/
        return "/mall/thing";
    }

    /**
     * 拼接三个框
     * @param model
     * @param qo
     * @return
     */
    @RequestMapping("thingTpl")
    public String thingTpl(Model model,@ModelAttribute("qo")MallGoodsQuery qo){
        //goods(没有简介)
        List<MallGoods> goods = mallGoodsService.queryByGoodsByDate(qo);
        model.addAttribute("goods", goods);
        return "mall/thingTpl";
    }

    /**
     * 保存到芒果中
     * @param model
     * @param virtualComment
     * @return
     */
    @RequestMapping("commentAdd")
    @ResponseBody
    public Object comment (Model model, VirtualComment virtualComment, @UserParam UserInfo userInfo){
        virtualComment.setUsername(userInfo.getNickname());
        virtualComment.setUserId(userInfo.getId());
        virtualComment.setLevel(userInfo.getLevel());
        virtualComment.setHeadUrl(userInfo.getHeadImgUrl());

        virtualCommentService.save(virtualComment);
        return new AjaxResult();
    }

    /**
     * 众筹保存到芒果中
     * @param model
     * @param virtualzcComment
     * @return
     */
    @RequestMapping("commentzcAdd")
    @ResponseBody
    public Object commentzc (Model model, VirtualzcComment virtualzcComment, @UserParam UserInfo userInfo){
        virtualzcComment.setUsername(userInfo.getNickname());;
        virtualzcComment.setUserId(userInfo.getId());
        virtualzcComment.setLevel(userInfo.getLevel());
        virtualzcComment.setHeadUrl(userInfo.getHeadImgUrl());

        virtualzcCommentService.save(virtualzcComment);
        return new AjaxResult();
    }
    /**
     * 众筹查出来数据然后拼接在模板中
     */
    @RequestMapping("zccomment")
    public String zccommtent (Model model, @ModelAttribute("qo")VirtualzcCommentQuery qo){
        Page<VirtualzcComment> page = virtualzcCommentService.query(qo);

        model.addAttribute("page",page);
        return "/mall/zhongchouTpl";
    }
    /**
     * 查出来数据然后拼接在模板中
     */
    @RequestMapping("comment")
    public String commtent (Model model, @ModelAttribute("qo")VirtualCommentQuery qo){
        Page<VirtualComment> page = virtualCommentService.query(qo);
        model.addAttribute("page",page);
        return "/mall/virtualGoodsTpl";
    }



    /**
     * 博游商城
     * @return
     */
    @RequestMapping("virtual")
    public String virtual(){
        return "/mall/virtual_goods";
    }

    /**
     * 我的道具页面
     * @return
     */
    @RequestMapping("virtual1Tpl")
    public String virtual1Tpl(){
        return "/mall/virtualGoods1Tpl";
    }

    /**
     * 道具商店页面
     * @return
     */
    @RequestMapping("virtual2Tpl")
    public String virtual2Tpl(){
        return "/mall/virtualGoods2Tpl";
    }

    @RequestMapping("zhongchou")
    public String zhongchou(){
        return "mall/zhongchou";

    }}
